package com.woniuxy.service.impl;

import com.woniuxy.dao.UserDao;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.entity.User;
import com.woniuxy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;


    @Override
    public ResponseEntity findOne(User user) {
        User user1 = userDao.findOne(user);
        if (user1 != null) {
            return new ResponseEntity<>(200, "查询成功", user1);
        }else {
            return ResponseEntity.FAIL;
        }
    }

    @Override
    public ResponseEntity findOne01(User user) {
        User user1 = userDao.findOne01(user);
        if (user1 != null) {
            return new ResponseEntity<>(200, "查询成功", user1);
        }else {
            return ResponseEntity.FAIL;
        }
    }

    @Override
    public ResponseEntity addOne(User user) {
        int i = userDao.addOne(user);
        if (i == 1){
            return new ResponseEntity<>(200, "添加成功", i);
        }else {
            return ResponseEntity.FAIL;
        }
    }

    @Override
    public ResponseEntity findAll() {
        List<User> list = userDao.findAll();
        if (list.size() !=0){
            return new ResponseEntity(200,"查询成功",list);
        }else {
            return ResponseEntity.FAIL;
        }
    }
}
